#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/2/15 10:40
# @Author  : ldh

from time import sleep
from basic.device.Android import Android



class awz_myinfo_page(Android) :
    # myBtm = "cn.cloudbae.lovewuzhou:id/menu_my"
    myBtm = "cn.cloudbae.lovewuzhou:id/tab4"
    goLogin = "cn.cloudbae.lovewuzhou:id/tvUserGoLogin"
    userName = "cn.cloudbae.lovewuzhou:id/tvUserName"
    userPhone = "cn.cloudbae.lovewuzhou:id/tvUserPhone"
    userId = "cn.cloudbae.lovewuzhou:id/tvUserId"
    gotoMyinfo = "cn.cloudbae.lovewuzhou:id/gotoMyInfoEditLinearLayout"
    rightText = "cn.cloudbae.lovewuzhou:id/item_right_text"
    nick_edit = "cn.cloudbae.lovewuzhou:id/nick_edit"
    nick_submit = "cn.cloudbae.lovewuzhou:id/nick_submit"

    # 点击打开我的页面
    @classmethod
    def open_mypage(cls) :
        cls.poco(cls.myBtm).click()
        sleep(2)

    # 判断用户是否已登录
    @classmethod
    def iflogin(cls) :
        if cls.poco(cls.goLogin).wait(3).exists() :
            return False
        else :
            return True

    # 点击【登录】按钮
    @classmethod
    def clickloginBtm(cls) :
        cls.poco(cls.goLogin).click()

    # 获取用户信息
    @classmethod
    def get_userinfo(cls) :
        username = cls.poco(cls.userName).get_text()
        print("昵称：" + username)
        userphone = cls.poco(cls.userPhone).get_text()
        print("手机号：" + userphone)
        text = cls.poco(cls.userId).get_text()
        userid = text.replace("ID", "").replace(" ", "")
        print("ID：" + userid)
        return userphone

    # 个人信息
    @classmethod
    def myinfo(cls) :
        cls.poco(cls.gotoMyinfo).click()
        sleep(3)
        text = cls.poco(cls.rightText)[1].get_text()
        print("账号/手机号：" + text)
        return text

    # 查看昵称
    @classmethod
    def nickName(cls) :
        nickname = cls.poco(cls.rightText)[2].get_text()
        print("昵称：" + nickname)
        return nickname

    # 修改昵称
    @classmethod
    def editNickName(cls) :
        cls.poco(cls.rightText)[2].click()
        cls.poco(cls.nick_edit).set_text("测试时的昵称")
        cls.poco(cls.nick_submit).click()
        nickname_new = cls.poco(cls.rightText)[2].get_text()
        print("修改昵称为：" + nickname_new)

    # 还原昵称
    @classmethod
    def nickNameBack(cls) :
        nickname = cls.poco(cls.rightText)[2].get_text()
        if nickname != "乌七玛嘿" :
            cls.poco(cls.rightText)[2].click()
            cls.poco(cls.nick_edit).set_text("乌七玛嘿")
            cls.poco(cls.nick_submit).click()
        nickname = cls.poco(cls.rightText)[2].get_text()
        print("昵称恢复为：" + nickname)
